package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcat.api.mysql.PmsProductFullReductionApi;
import com.itcat.mapper.PmsProductFullReductionMapper;
import com.itcat.mysql.pojo.PmsProductAttributeValue;
import com.itcat.mysql.pojo.PmsProductFullReduction;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-04 0:21
 */
@DubboService
public class PmsProductFullReductionApiImpl implements PmsProductFullReductionApi {

    @Autowired
    private PmsProductFullReductionMapper pmsProductFullReductionMapper;


    /**
     * 保存商品满减价格设置
     * @param productFullReductionList
     */
    @Override
    public void saveList(List<PmsProductFullReduction> productFullReductionList) {
        pmsProductFullReductionMapper.batchInsert(productFullReductionList);
    }

    /**
     *  获取商品满减价格设置
     * @param productId
     * @return
     */
    @Override
    public List<PmsProductFullReduction> findByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductFullReduction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductFullReduction::getProductId, productId);
        List<PmsProductFullReduction> pmsProductFullReductionList = pmsProductFullReductionMapper.selectList(queryWrapper);
        return pmsProductFullReductionList;
    }

    /**
     * 更新商品满减价格设置
     * @param productFullReductionList
     */
    @Override
    public void updateList(List<PmsProductFullReduction> productFullReductionList) {
        pmsProductFullReductionMapper.batchUpdate(productFullReductionList);
    }

    /**
     * 删除响应商品id的数据
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductFullReduction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, PmsProductFullReduction::getProductId, productId);
        pmsProductFullReductionMapper.delete(queryWrapper);
    }
}
